
Khan S. Alam 20 https://E-next.in
Algorithm of Count :-
algorithm listCount( val pList <head pointer>)
Returns integer representing number of nodes in list
Pre : pList is a pointer to a valid list head structure
Return : count for number of nodes in list
1. return ( pList ->count)
end listCount
Algorithm of Append:-
algorithm append ( val pList1<head pointer>, val pList2 <head pointer>)
This algorithm appends the second list at the end of the first
Pre : pList1 and pList2 are pointers to valid lists
Post : Second list appended to nth first list
1. if(pList1 -> count zero)
1. pList1->head = pList2->head
else
1.pLoc = pList1->head
2. loop(pLoc ->link not null)
1. pLoc=pLoc->link
3. pLoc->link = pList2->head
3. pList1->count = pList1 ->count + pList2->count
4. return
End append
Algorithm of Sort:
Algorithm sortlist()
It will sort the elements of doubly linked list
Pre: front is pointer to a linked list structure pointer.
Ploc is a pointer variable to receive current node
Target is the key being sought.
Inode and jnode are pointers of structure.
Ploc: ploc points to first node with equal or greater key
Or NULL if target > key of last node
Temp: is a temporary pointer
1. ploc=front
2. loop( inode equal to ploc and inode not equal to NULL)
1. loop( jnode equal to ploc and jnode not equal to NULL)
1. if ( inode->data.key > jnode->data.key)
1.temp->data.key=inode->data.key
2.inode->data.key=jnode->data.key
3.jnode->data.key=temp->data.key
3. return
End sortlist